$(function () {
    obj.init();
});
var obj = new function () {
    'use strict';
    return {
        source:null,
        chart :null,
        config:null,
        dataGrid:null,
        params: {
            startDay: null,
            endDay: null,
            tag   : null
        },
        color: {
            'dep':['#59ADF3'],
            'country':['#FF999A'],
            'diver':['#AF89D6'],
            'carType':['#FFCC67'],
            'carState':['#86D560']
        },
        init:function () {
            this.params.tag = tag;
            this.params.startDay = $('#startDay').val();
            this.params.endDay   = $('#endDay').val();
            this.funObj().loadChart();
            this.listener();
        },
        listener:function () {
            var $this = this;
            //查看点击
            $('#bt_view').click(function () {
                $this.funObj().reloadChart();
            });

            //导出
            $('#excel_export').click(function () {
                $this.funObj().exportExcel();
            });
            
            $('#bt_back').click(function () {
                $this.funObj().back();
            });
        },
        funObj:function () {
            var $this = this;
            return {
                loadChart:function () {
                    if(!showList){
                        $this.config  = {showLegends: false, showZoom:false, seriesFontSize: 15,color:$this.color[$this.params.tag]};
                        $this.source  = {url: baseUrl + 'lm/state_car/getData', params: $this.params};
                        if($this.params.tag == 'carState' || $this.params.tag == 'country' ){
                            $this.config.showZoom = true;
                        }
                        if($this.params.tag == 'dep'){
                            $this.config.xFontSize =10;
                        }
                        $this.chart   = (new xhChart).bar('chart', $this.source, $this.config);
                    }else {
                        $this.config  = {showLegends: false, showZoom:false, seriesFontSize: 15,color:$this.color[$this.params.tag]};
                        $this.source  = {url: baseUrl + 'lm/state_car/getData', params: $this.params};
                        $('#toolBar').show();
                        $('.xh-datagrid').parent().show();
                        $this.dataGrid = new xhDataGrid($('#list'), 'lm/state_car/getDgData',$this.params);
                        $this.dataGrid.parseToolbar().init();
                        if($this.params.tag == 'carState' || $this.params.tag == 'country'){
                            $this.config.showZoom = true;
                        }
                        $this.chart   = (new xhChart).bar('chart', $this.source, $this.config);
                    }
                },
                reloadChart:function () {
                    $this.params.startDay = $('#startDay').val();
                    $this.params.endDay   = $('#endDay').val();
                    $this.funObj().loadChart();
                    $this.dataGrid.reload($this.params);
                },
                exportExcel:function () {
                    window.open(baseUrl+'lm/state_car/exportExcel/'+$this.params.tag+'/'+$this.params.startDay+'/'+$this.params.endDay);
                },
                back:function () {
                    window.top.xhTop.getActiveFrame().location.href=baseUrl+'lm/state_car';
                }
            };
        }
    }
};